{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "cfa0f266",
   "metadata": {},
   "source": [
    "### 购物车程序项目\n",
    "#### 要求：1、运行程序后，让用户输入支付宝余额，然后打印我们的商品列表给用户。\n",
    "#### 　　   2、让用户输入商品编号进行商品的购买。\n",
    "#### 　　   3、用户选择商品后，检查用户的余额是否够，若够则直接扣款，不够则提醒用户。\n",
    "#### 　　   4、用户可以随时退出购买，退出时打印用户已购买的商品和支付宝余额。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e5536666",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 商品信息的数据存放（编号，名称，价格）\n",
    "# 列表嵌套\n",
    "# 每一个商品的内容是一个多个值的值，可选用list\n",
    "# 重复代码必想到for\n",
    "\n",
    "#用户输入 #打印包装 # 列表，列表中的列表\n",
    "#价格与余额比较\n",
    "#提醒用户append\n",
    "#循环for 或 while true（在哪插入？）\n",
    "# 购物车found 余额多少"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "ddbe1a59",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-10-25T15:43:34.334448Z",
     "start_time": "2021-10-25T15:43:18.821561Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入支付宝余额：30\n",
      "------商品清单------\n",
      "编号：0, 名称：汉堡, 价格：10 \n",
      "编号：1, 名称：香肠, 价格：3 \n",
      "编号：2, 名称：可乐, 价格：7 \n",
      "编号：3, 名称：薯条, 价格：9 \n",
      "请输入正确的商品编号进行购买（退出请按q）：2\n",
      "【可乐】加购成功，您的【余额】还剩23元\n",
      "编号：0, 名称：汉堡, 价格：10 \n",
      "编号：1, 名称：香肠, 价格：3 \n",
      "编号：2, 名称：可乐, 价格：7 \n",
      "编号：3, 名称：薯条, 价格：9 \n",
      "请输入正确的商品编号进行购买（退出请按q）：1\n",
      "【香肠】加购成功，您的【余额】还剩20元\n",
      "编号：0, 名称：汉堡, 价格：10 \n",
      "编号：1, 名称：香肠, 价格：3 \n",
      "编号：2, 名称：可乐, 价格：7 \n",
      "编号：3, 名称：薯条, 价格：9 \n",
      "请输入正确的商品编号进行购买（退出请按q）：q\n",
      "购物车：[['可乐', 7], ['香肠', 3]]，您的【余额】还剩20 元\n"
     ]
    }
   ],
   "source": [
    "Alipay = int(input(\"请输入支付宝余额：\"))\n",
    "\n",
    "goods_list = [['汉堡',10],['香肠',3],['可乐',7],['薯条',9]]\n",
    "\n",
    "info = '''------商品清单------'''\n",
    "print(info)\n",
    "\n",
    "user_shopping_cart = []\n",
    "\n",
    "while True:\n",
    "    for i in range(len(goods_list)):\n",
    "        print(\"编号：%s, 名称：%s, 价格：%s \"%(i,goods_list[i][0],goods_list[i][1]))\n",
    "    choice = input(\"请输入正确的商品编号进行购买（退出请按q）：\")\n",
    "    if choice.isdigit():\n",
    "        choice = int(choice)\n",
    "        if choice > len(goods_list):\n",
    "            print(\"该商品不存在，请输入正确的商品编号\")\n",
    "        else:\n",
    "            if Alipay > goods_list[choice][1]:\n",
    "                Alipay = Alipay - goods_list[choice][1]\n",
    "                user_shopping_cart.append(goods_list[choice])\n",
    "                print(\"【%s】加购成功，您的【余额】还剩%s元\"%(goods_list[choice][0],Alipay))\n",
    "            else:\n",
    "                print(\"您的【余额】不足，请更换支付方式后再试\")\n",
    "    elif choice ==  \"q\":\n",
    "        print(\"购物车：%s，您的【余额】还剩%s 元\"%(user_shopping_cart,Alipay))\n",
    "        break\n",
    "    else:\n",
    "        print(\"该商品不存在1，请输入正确的商品编号\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c50b0293",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8627db6c",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
